/**
 * Bakalarska prace - Inteligentni budik
 * @package sleepCatcher
 * @file FormCatchSleep.h
 * @author Jan Pesava - xpesav00
 * @email xpesav00@stud.fit.vutbr.cz
 * @date 24. 12. 2011
 */

#ifndef FORMCATCHSLEEP_H_
#define FORMCATCHSLEEP_H_

#include <FUi.h>
#include <FUix.h>
#include <FBase.h>
#include <FApp.h>
#include <FGraphics.h>
#include <FUiITouchEventListener.h>

#include "models/SCAlarm.h"
#include "forms/FormCatchSleep.h"
#include "SCDataCollector.h"
#include "models/SCSleepView.h"
#include "models/SCResampler.h"

using namespace Osp::Uix;
using namespace Osp::Ui::Controls;
using namespace Osp::Ui;
using namespace Osp::App;
using namespace Osp::Graphics;

class FormCatchSleep :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
	public Osp::Uix::ISensorEventListener,
	public Osp::Base::Runtime::ITimerEventListener,
	public Osp::Ui::ITouchEventListener
{

// Construction
public:
	FormCatchSleep();
	virtual ~FormCatchSleep();

// Attributes
private:
	SensorManager *pSensorManager;
	SCDataCollector *pDataCollector;
	SCSleepView* pSleepView;
	SCResampler* pSleepViewResampler;
	SCResampler* pDataResampler;
	SCAlarm *pActiveSCAlarm;
	SCSample *pLastSample;
	Label* pAlarmText;
	Label* pAlarmImg;
	Label* pDateText;
	Label* pDateImg;
	Label* pSamplesCount;
	Label* pLabelBG;
	bool isCatchStart;
	Timer* pTimer;
	Canvas* pScreenSaver;
	Bitmap* pScreenSaverPicture;
	int defaultScreenBrightness;

// Methods
public:
	bool Initialize(void);
	virtual result OnInitializing(void);
	virtual result OnTerminating(void);
	void OnActionPerformed(const Osp::Ui::Control& source, int actionId);
	void OnDataReceived (SensorType sensorType, SensorData &sensorData, result r);
	void OnTouchDoublePressed (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTouchFocusIn (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTouchFocusOut (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTouchLongPressed (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTouchMoved (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTouchPressed (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTouchReleased (const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const TouchEventInfo &touchInfo);
	void OnTimerExpired (Timer &timer);
	bool InitializeSensors();
	void SetActiveAlarm();
	void SetCurrentDateTime();
	float ComputeEnergy(SCSample *pLastSample, SCSample *pCurrentSample);
	int GetFormId();
	void StartCatch();
	void StopCatch();
	void StartScreenSaver();
	void StopScreenSaver();
	void RemoveListeners();
	result OnDraw();
	void Update();
	void Redraw();

};

#endif /* FORMCATCHSLEEP_H_ */
